package org.ezest.masteringextjs.rs;

import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.ezest.masteringextjs.dao.UserDao;
import org.ezest.masteringextjs.dao.impl.UserDaoImpl;
import org.ezest.masteringextjs.model.User;

@Path("/json/user")
public class UserResource {

	UserDao userDao = new UserDaoImpl();
	
	@POST
	@Path("/login")
	@Produces(MediaType.APPLICATION_JSON)
	public String findById(@FormParam("user") String userName, @FormParam("password") String password) {
		User user = userDao.findByUserName(userName);
		if(user != null) {
			if(user.getPassword().equals(password)){
				return "{success : true}";
			}
		}
		return "{success : false}";
	}
	
	@GET
	@Path("/logout")
	@Produces(MediaType.APPLICATION_JSON)
	public String logout() {
		System.out.println("Inside logout!!");
		return "{success : true}";
	}
}
